import dayjs from 'dayjs'
import type { DirectiveHook } from 'vue'

const handler: DirectiveHook = (el, binding) => {
  if (!binding.value || binding.value === '0') {
    el.textContent = '-'
    return
  }
  const format = binding.arg || 'YYYY-MM-DD HH:mm:ss'
  el.textContent = dayjs(binding.value * 1000).format(format)
}

export default handler
